import {ecs} from "db://oops-framework/libs/ecs/ECS";
import {Server} from "db://assets/script/network/ws/server";

// 监听金豆房
@ecs.register("MjListenRubyDeskComp")
export class MjListenRubyDeskComp extends ecs.Comp {
    reset(): void {
        // 删除监听的路由
        for (const route of Object.keys(this.routes)) {
            Server.listenOff(route)
        }
        this.routes = {}
    }

    routes: {}

    listenRoute(route: string, cb: Function) {
        if (!this.routes) {
            this.routes = {}
        }
        if (!this.routes[route]) {
            this.routes[route] = true
        }
        Server.listen(route, cb)
    }
}
